package com.callAnalyzer;

import java.util.Date;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Test extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
//		String arr[]=  new String[1] ;//{"Android","iPhone","BlackBerry","AndroidPeople"}; 

		try{ 
			String s=CallLog.CONTENT_URI.toString(); 
			Cursor c = getContentResolver().query(/*Uri.parse("content://call_log/calls")*/CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE+" Desc");
			
			//getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder)
			startManagingCursor(c);
			
			ContentResolver cr=getContentResolver();
			
			
			String arr[]=  new String[c.getCount()+1] ;
			ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr);
			ListView lst= ((ListView)findViewById(R.id.list));//.setAdapter(ad);
			lst.setAdapter(ad);
			int counter=0;
			arr[counter++]="Number of enteries cursor returned "+c.getCount();  
			//arr={"Thomas"};
			
			
			//ad.notifyDataSetChanged();
			
			//lst.notify();
			
			if(c.moveToFirst())
			{
				do 
				{
					Date number =  new Date( Long.parseLong(c.getString(c.getColumnIndex(CallLog.Calls.DATE) )));
					arr[counter++]=String.valueOf(number);
					//ad.notifyDataSetChanged();
					//((ListView) findViewById(R.id.list))
				}while(c.moveToNext());
			} 
			
		}
		
		catch(Exception e)
		{
			Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();

		}
	}


}